/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.cemaden.library.dao.previsao;

import br.gov.cemaden.library.model.alerta.Agencia;
import br.gov.cemaden.library.model.previsao.AquisicaoPrecipitacao;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;

/**
 *
 * @author alan.oliveira
 */
public class AquisicaoPrecipitacaoDAO {
    
    private final EntityManager em;

    public AquisicaoPrecipitacaoDAO(EntityManager em) {
        this.em = em;
    }
    
    public AquisicaoPrecipitacao find(Date datahoraArquivo, Agencia agencia) {
        
        AquisicaoPrecipitacao object = null;
        
        TypedQuery<AquisicaoPrecipitacao> query;
        query = em.createQuery("FROM " + AquisicaoPrecipitacao.class.getName() + " WHERE datahoraArquivo = :datahoraArquivo and agencia = :agencia", AquisicaoPrecipitacao.class);
        query.setParameter("datahoraArquivo", datahoraArquivo);
        query.setParameter("agencia", agencia);

        try {
            object = query.getSingleResult();
        }
        catch (NoResultException ex) {
            
        }
        
        return object;
    }
    
}
